﻿#include "knowledgebaseconfigwidget.h"
#include "ui_knowledgebaseconfigwidget.h"
#include <QFileDialog>
#include <QDesktopServices>
#include "constants.h"

KnowledgebaseConfigWidget::KnowledgebaseConfigWidget(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::KnowledgebaseConfigWidget)
{
    ui->setupUi(this);

    // 设置默认路径 为 mydoc下
    QString rootDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
    rootDir += "\\";
    rootDir += QLUOSHU_ROOT_DIR;
    this->ui->lineEditQLuoshuRoot->setText(rootDir);
}


KnowledgebaseConfigWidget::~KnowledgebaseConfigWidget()
{
    delete ui;
}


void KnowledgebaseConfigWidget::on_toolButton_clicked()
{
    // 显示路径选择
    QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly;
    //options |= QFileDialog::DontUseNativeDialog;
    QString directory = QFileDialog::getExistingDirectory(this,
                                tr("Select a Directory"),
                                this->ui->lineEditQLuoshuRoot->text(),
                                options);
    if (!directory.isEmpty())
        this->ui->lineEditQLuoshuRoot->setText(directory);
}

QString KnowledgebaseConfigWidget::getRootDir()
{
    return this->ui->lineEditQLuoshuRoot->text();
}

void KnowledgebaseConfigWidget::on_pushButton_clicked()
{
    QString strRootDir = this->ui->lineEditQLuoshuRoot->text();
    QDir rootDir(strRootDir);
    if (!rootDir.exists())
    {
        rootDir.mkdir(strRootDir);
    }
}
